package lesson;

import java.sql.*;
import java.util.ArrayList;

public class JDBCDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");

        String url = "jdbc:mysql:///db1?useSSL=false";
        String user = "root";
        String psd = "1234";
        Connection connection = DriverManager.getConnection(url,user,psd);

        String sql = "select * from account";

        Statement st = connection.createStatement();

        ResultSet rs = st.executeQuery(sql);

        ArrayList<Account> list = new ArrayList<>();
        while (rs.next()){
            Integer id = rs.getInt("id");
            String name = rs.getString("name");
            String money = rs.getString("money");

            Account account = new Account();
            account.setId(id);
            account.setName(name);
            account.setMoney(money);

            list.add(account);
        }

        System.out.println(list);
        rs.close();
        st.close();
        connection.close();
    }
}
